﻿@using GridMvc.Html
@model BeYourMarket.Web.Areas.Admin.Models.PluginsGrid

@section Styles {
    <link href="~/Content/Gridmvc.css" rel="stylesheet" />
    <link href="~/Content/gridmvc.datepicker.min.css" rel="stylesheet" />
}

@{
    ViewBag.Title = "[[[Plugins]]]";
}

@helper DisplayInstallerLink(string systemName, bool installed)
{
    if (installed)
    {
        <a class="btn btn-sm btn-danger" href="@Url.Action("Installer", "Plugin", new { systemName = systemName, pluginAction = (int)BeYourMarket.Model.Enum.Enum_PluginAction.Uninstall })"><i class="fa fa-times-circle"></i> [[[Uninstall]]]</a>
    }
    else
    {
        <a class="btn btn-sm btn-primary" href="@Url.Action("Installer", "Plugin", new { systemName = systemName, pluginAction = (int)BeYourMarket.Model.Enum.Enum_PluginAction.Install })"><i class="fa fa-plus-circle"></i> [[[Install]]]</a>
    }
}

@helper DisplayEnableLink(string systemName, bool installed, bool enabled)
{
    if (installed) { 
        if (enabled)
        {
            <a class="btn btn-sm btn-danger" href="@Url.Action("Installer", "Plugin", new { systemName = systemName, pluginAction = (int)BeYourMarket.Model.Enum.Enum_PluginAction.Disabled })"><i class="fa fa-times-circle"></i> [[[Disable]]]</a>
        }
        else
        {
            <a class="btn btn-sm btn-primary" href="@Url.Action("Installer", "Plugin", new { systemName = systemName, pluginAction = (int)BeYourMarket.Model.Enum.Enum_PluginAction.Enabled })"><i class="fa fa-plus-circle"></i> [[[Enable]]]</a>
        }
    }
}

@helper DisplayConfigureLink(string systemName, bool installed)
{
    if (installed)
    {
        <a class="btn btn-sm btn-primary m-b-5" href="@Url.Action("Configure", "Plugin", new { systemName = systemName })"><i class="fa fa-gear"></i> [[[Configure]]]</a>
    }
}

@helper DisplayDescription(BeYourMarket.Core.Plugins.PluginDescriptor descriptor)
{
    @descriptor.Description
    <br />
    <small>
        [[[Version]]]: @descriptor.Version | [[[Author]]]: @descriptor.Author
        <br />
        [[[PluginFileName]]]: @descriptor.PluginFileName
    </small>
}


<div class="wraper container-fluid">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-plug"></i> [[[Plugins]]]</h3>
                </div>
                <div class="panel-body">
                    @Html.Partial("_UserMessage")

                    <div class="alert alert-info">
                        <p>[[[Here you can manage all the plugins. To add/develop a new plugin, please read the documentation.]]]</p>
                    </div>

                    <div class="row">
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            @Html.Grid(Model).SetLanguage(Context.GetPrincipalAppLanguageForRequest().ToString()).EmptyText("[[[There are no items to display.]]]").Columns(columns =>
                       {
                           columns.Add()
                            .Encoded(false)
                            .Sanitized(false)
                            .RenderValueAs(x => DisplayConfigureLink(x.SystemName, x.Installed));

                           columns.Add()
                             .Encoded(false)
                             .Sanitized(false)
                             .RenderValueAs(x => DisplayEnableLink(x.SystemName, x.Installed, x.Enabled));
                           
                           columns.Add()
                             .Encoded(false)
                             .Sanitized(false)
                             .RenderValueAs(x => DisplayInstallerLink(x.SystemName, x.Installed));                           

                           columns.Add(x => x.Group).Titled("[[[Group]]]");

                           columns.Add(x => x.SystemName).Titled("[[[SystemName]]]");

                           columns.Add(x => x.Description)
                             .Encoded(false)
                             .Sanitized(false)
                             .RenderValueAs(x => DisplayDescription(x)).Titled("[[[Description]]]");

                           columns.Add(x => x.DisplayOrder).Titled("[[[Ordering]]]");

                           columns.Add(x => x.Installed)
                             .Encoded(false)
                             .Sanitized(false)
                             .RenderValueAs(x => RazorHelper.DisplayYesNo(x.Installed)).Titled("[[[Installed]]]");


                       }).Sortable().Filterable().WithPaging(10).Selectable(false)
                        </div>
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>

@section Scripts {
    <script src="~/Scripts/gridmvc.min.js"></script>    
    @Html.Partial("_LocalizationGridMvc")
}